const path = require("path");
const fs = require("fs-extra");

/*
 * @FilePath: /api-gen/src/config/api.js
 * @Author: 张文鑫
 * @Date: 2025-03-04 11:18:25
 * @Description:
 */

// 从项目的package.json中读取配置
function getConfigFromPackageJson() {
  try {
    const packageJsonPath = path.resolve(process.cwd(), "package.json");
    if (fs.existsSync(packageJsonPath)) {
      const packageJson = require(packageJsonPath);
      return packageJson.zwxApiGen || {};
    }
  } catch (error) {
    console.error("读取package.json失败:", error.message);
  }
  return {};
}

const config = getConfigFromPackageJson();

// Swagger 配置
exports.SWAGGER_URL = process.env.SWAGGER_URL || config.url;

// 可以直接提供完整的 base64 编码认证令牌
exports.SWAGGER_AUTH_TOKEN = process.env.SWAGGER_AUTH_TOKEN || config.auth || "Y3NmcTpjc2ZxQEtqMjAyNQ==";
